import userMap from './user.json'
export default [
  {
    url: '/api/register',
    method: 'post',
    response: request => {
      const { username, password } = request.body
      const hasUsername = Object.keys(userMap).indexOf(username) > -1
      if (!hasUsername) {
        userMap[username] = password
        return {
          code: 200,
          message: '注册成功',
          data: {},
          isSuccess: true,
        }
      }
      return {
        code: 200,
        message: '用户名已存在',
        data: {},
        isSuccess: false,
      }
    },
  },
  {
    url: '/api/login',
    method: 'post',
    response: request => {
      const { username, password } = request.body
      const hasUsername = Object.keys(userMap).indexOf(username) > -1
      if (hasUsername) {
        if (userMap[username] === password) {
          return {
            code: 200,
            message: 'ok',
            data: {
              role: 'superAdmin',
              token: '@guid',
            },
            isSuccess: true,
          }
        }
      }

      return {
        code: 200,
        message: '账号或密码错误',
        data: {},
        isSuccess: false,
      }
    },
  },
  {
    url: '/api/getUserInfo',
    method: 'get',
    response: request => {
      return {
        code: 200,
        message: 'ok',
        data: {
          'role|1': ['superAdmin', 'admin', 'visitor'],
        },
        isSuccess: true,
      }
    },
  },
  {
    url: '/api/getUsers',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: 'ok',
        data: {
          'rows|10': [
            {
              id: '@guid',
              name: '@cname',
              'age|20-30': 23,
              'job|1': ['前端工程师', '后端工程师', 'UI工程师', '需求工程师'],
            },
          ],
        },
        isSuccess: true,
      }
    },
  },
]
